#ifndef HEIGHTFIELD_H_
#define HEIGHTFIELD_H_

#include <string>
#include <fstream>
#include <iostream>
using namespace std;


#include "Primitive.h"
#include "Vector.h"
#include "Point.h"
#include "BoundingBox.h"
class Ray;

class Heightfield : public Primitive {
 public:
  Heightfield(Material* material, const Point& corner1, const Point& corner2, string file);
  virtual ~Heightfield();

  virtual void getBounds(BoundingBox& bbox) const;
  virtual void intersect(HitRecord& hit, const RenderContext& context, const Ray& ray) const;
  virtual void normal(Vector& normal, const RenderContext& context,
                      const Point& hitpos, const Ray& ray, const HitRecord& hit) const;
 protected:
	 void initialize(std::string);
	 
	 BoundingBox bbox;
  string file;
  float** data;
  int nx, ny;
  Vector diag;
  Vector cellsize;
  Vector inv_cellsize;
  
};

struct HitData {
	  int x, y;
  };
  
#endif /*HEIGHTFIELD_H_*/
